﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CRM.Entity;
using CRM.BLL;
using DP.Web.UI;
using DP.Common;

namespace CRM.Web.MachineConfigManage
{
    public partial class Modify : Common.PageBase
    {

        T_MACHINECONFIG_BLL bll = new T_MACHINECONFIG_BLL();
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            PageHelper.SetPrePageUrl(this.Page);
            PageHelper.SetGoBackUrl(this.Page, btnCancel, StaticConstant.NotBackUrl);
            PageHelper.SetPopCalender(this.Page, txtCHASSISREGISTERDATE);
            PageHelper.SetPopCalender(this.Page, txtCREATETIME);
            PageHelper.SetPopCalender(this.Page, txtLASTMODIFYTIME);

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {


                pageDataInit();
            }
        }

        #region 页面初始化数据绑定






        #endregion

        private void pageDataInit()
        {
            string _autoid = String.IsNullOrEmpty(Request.QueryString["AUTOID"]) ? "" : Request.QueryString["AUTOID"].Trim();

            if (!String.IsNullOrEmpty(_autoid))
            {
                T_MACHINECONFIG_Entity entity = bll.GetEntity("AUTOID", _autoid);

                PageHelper.SetControlValue<T_MACHINECONFIG_Entity>(this.Page, entity);
                lblTitle.Text = "整车配置信息修改";
            }
            else
            {
                lblTitle.Text = "整车配置信息添加";
                txtCREATEPEOPLE.Enabled = false;
                txtCREATETIME.Enabled = false;
                txtLASTMODIFYPEOPLE.Enabled = false;
                txtLASTMODIFYTIME.Enabled = false;
                txtBUSINESSDIVISIONNAME.Enabled = false;
                txtDEPARTMENTNAME.Enabled = false;
            }

            txtAUTOID.ReadOnly = true;

        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            string _autoid = String.IsNullOrEmpty(Request.QueryString["AUTOID"]) ? "" : Request.QueryString["AUTOID"].Trim();


            T_MACHINECONFIG_Entity entity = bll.GetEntity("AUTOID", _autoid);

            if (entity != null)
            {
                PageHelper.GetControlValue<T_MACHINECONFIG_Entity>(this.Page, ref entity);
                entity.LASTMODIFYPEOPLE = _userLoginInfo.UserEntity.USERNAME;
                entity.LASTMODIFYPEOPLEID = _userLoginInfo.UserEntity.USERID;
                entity.LASTMODIFYTIME = DateTime.Now;
                try
                {
                    long rel = bll.Update(entity);
                    if (rel > 0)
                    {
                        PageHelper.ShowMessage(this.Page, "修改成功！", UserLoginInfo.FilterBackUrl(PageHelper.GetPrePageUrl(this), "list.aspx"));
                    }
                    else
                    {
                        PageHelper.ShowMessage(this.Page, "修改失败！");
                    }
                }
                catch (Exception ex)
                {

                    PageHelper.ShowMessage(this.Page, "修改失败！" + ex.Message);
                }
            }
            else
            {
                entity = new T_MACHINECONFIG_Entity();

                PageHelper.GetControlValue<T_MACHINECONFIG_Entity>(this.Page, ref entity);
                entity.CREATEPEOPLE = _userLoginInfo.UserEntity.USERNAME;
                entity.CREATEPEOPLEID = _userLoginInfo.UserEntity.USERID;
                entity.CREATETIME = DateTime.Now;
                entity.LASTMODIFYPEOPLE = _userLoginInfo.UserEntity.USERNAME;
                entity.LASTMODIFYPEOPLEID = _userLoginInfo.UserEntity.USERID;
                entity.LASTMODIFYTIME = DateTime.Now;
                entity.BUSINESSDIVISIONCODE = _userLoginInfo.UserEntity.BUSINESSDIVISIONCODE;
                entity.BUSINESSDIVISIONID = _userLoginInfo.UserEntity.BUSINESSDIVISIONID;
                entity.BUSINESSDIVISIONNAME = _userLoginInfo.UserEntity.BUSINESSDIVISIONNAME;
                entity.DEPARTMENTCODE = _userLoginInfo.UserEntity.DEPARTMENTCODE;
                entity.DEPARTMENTID = _userLoginInfo.UserEntity.DEPARTMENTID;
                entity.DEPARTMENTNAME = _userLoginInfo.UserEntity.DEPARTMENTNAME;

                try
                {
                    long rel = bll.Insert(entity);
                    if (rel > 0)
                    {
                        PageHelper.ShowMessage(this.Page, "添加成功！", "list.aspx");
                    }
                    else
                    {
                        PageHelper.ShowMessage(this.Page, "添加失改！");
                    }
                }
                catch (Exception ex)
                {

                    PageHelper.ShowMessage(this.Page, "添加失改！" + ex.Message);
                }


            }
        }
    }
}
